<template>
<div class="save-wrapper ui container" v-if="show">
  <div class="ui very relaxed  grid">
    <div class="sixteen wide column">

      <form action="" class="ui form" @submit.prevent="submit_confirm">
        <div class="ui header">{{titleType}}菜单</div>

        <div class="fluid field">
          <label for="">标题</label>
          <input type="text" v-model="vo.title"  name="title" placeholder="请输入标题">
        </div>

        <!--<div class="fluid field">-->
          <!--<label for="">模块</label>-->
          <!--<input type="text" v-model="vo.module" name="module" placeholder="请输入链接">-->
        <!--</div>-->

        <div class="fluid field">
          <label for="">模型</label>
          <fselect fname="ctl" keyname="name" :val="vo.ctl" @selectValsChange='selectValsChange' placeholder="请选择模型" :data="allModel" v-if="allModel"></fselect>

        </div>
        <div class="fluid field">
          <label for="">父级</label>
          <fselect fname="pid" :val="vo.pid" @selectValsChange='selectValsChange' placeholder="请选择父级" :data="pdata" v-if="pdata"></fselect>
          <!-- <fselect fname="type" @selectValsChange='valChane' :val="vo.type" :data="typeData" placeholder="请选择类型"></fselect> -->

        </div>
          <myenum :param="{}" v-if="enumField_show_env.fval!==undefined" :field="enumField_show_env" @setVo='setEnum' ></myenum>
        <div class="fluid field">
          <label for="">自定义路由(可选)</label>
          <input type="text" v-model="vo.route" name="route" placeholder="请输入自定义路由">
        </div>

        <p class="submitRow">
          <button type="submit" :class="{loading:loadingBtn}" class="ui button">提 交</button>
        </p>
      </form>


    </div>
  </div>
</div>
</template>
<script type="text/ecmascript-6">
import fselect from 'components/form/select';
import myenum from 'components/field/enum';
import tool from 'src/util/tool';
import util from '_util/index';
import logic from '_logic';

import {
  mapState,
  mapMutations,
  mapGetters,
  mapActions
} from 'vuex'

export default {
  data() {
    return {
      result: '',
      type: 'add',
      model: {},
      pidinfo: {
        title: '父级',
        name: 'pid'
      },
        enumField_show_env:{
            name:'show_env',
            title:'显示环境',
            enum_type:1,
            enum_val:[
                '所有','测试','正式'
            ]
        },
      tabs: [],
      vo: null,
      fields: {},
      result_type: 'rs_error',
      curIndex: '1',
      loadingBtn: false,
      show: true
    }
  },
  methods: {
      setEnum(name, val) {
          this.vo[name]= val;
      },
    selectValsChange(val,fname) {
      this.vo[fname] = val
    },
    submit_confirm() {
      util.showConfirm(this, () => {
        this.onSubmit()
      },{content:'确认提交吗？'});
    },
    onSubmit() {
      let eventVue = util.store.get(this,'eventVue');

      logic.edit.setSaveLoading(this);

      let op = this.$store.state.global.op || 'insert';
      let url = tool.getApi(this,'Menu', op);

      if(!this.vo.pid) {
        this.vo.pid=0
      }

      util.http.SR(this, url, this.vo, '操作成功',()=>{
          this.loadingBtn = false;
        eventVue.$emit('afterAdd')
      });

    },

  },
  computed: {
    titleType() {
      return this.$store.state.global.op == 'update' ? '更新' : '添加';
    },
    ctl() {
      return this.$route.query.ctl;
    },
    pdata() {
      return this.$store.state.global.menus || {};
    },
    allModel() {
      return this.$store.state.global.model_all || {};
    }

  },
  components: {
    fselect,myenum
  },
  props: ['leftMenu', 'user', 'path', 'isAdd'],
  created() {

      util.store.dispatch(this, 'get_all_model',{});
      this.vo = util.store.get(this, 'editVo');
      this.enumField_show_env.fval = this.isAdd ? 0 : this.vo['show_env'];

  }
}
</script>
<style rel="stylesheet/less" scoped lang="less">@import "../../common/style/mixin";
@dir: "edit/";
form {
    .submitBtn();
}
</style>
